from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
from .page_base import BasePage

class ArticleManagePage(BasePage):
    
    def __init__(self,driver=None):
        super(ArticleManagePage,self).__init__(driver)
        self.switch_to_article_manage()
        sleep(1)
        
    @property
    def sub_title_element(self):
        WebDriverWait(self.driver,3).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div/div/div/div/div[2]/div/main/div[1]/div[1]/h3")))
        return self.find_element(By.XPATH,"/html/body/div/div/div/div/div[2]/div/main/div[1]/div[1]/h3")
    
    @property
    def search_box_input(self):
        return self.find_element(By.XPATH,"/html/body/div[1]/div/div/div/div[2]/div/main/div[1]/div[2]/span/span/input")
    
    @property
    def search_btn(self):
        return self.find_element(By.XPATH,"/html/body/div[1]/div/div/div/div[2]/div/main/div[1]/div[2]/span/span/span/button")
    
    @property
    def delete_article_btn(self):
        return self.find_element(By.XPATH,"/html/body/div[1]/div/div/div/div[2]/div/main/div[3]/div/div/div/div/div/table/tbody/tr[2]/td[2]/div/div[1]")
    
    @property
    def confirm_delete_article_btn(self):
        return self.find_element(By.XPATH,"/html/body/div[3]/div/div[2]/div/div/div/div[2]/button[2]")
    
    @property
    def cancel_delete_article_btn(self):
        return self.find_element(By.XPATH,"/html/body/div[3]/div/div[2]/div/div/div/div[2]/button[1]")
    
    
    def switch_to_article_manage(self):
        WebDriverWait(self.driver,3).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div/div/div/div/div[1]/aside/div/ul/li[3]/span")))
        btn = self.find_element(By.XPATH,"/html/body/div/div/div/div/div[1]/aside/div/ul/li[3]/span")
        btn.click()